<?php
/**
 * RedCross Application
 *
 * @copyright Copyright (c) 2010, Kristian Stokke Tryggestad, Rune Vikestad, Andreas Flaten Wist, Simen Nicolai Echholt, Ole Henrik Jahren
 */


class Core_Gateway_PasswordReset extends RedCross_Gateway_GatewayAbstract
{

    public function __construct()
    {
        $this->_class = 'PasswordReset';
        $this->_modelPath = 'Core_Model';
    }

    public function fetchRequest($userId, $resetKey) {
        $result = Doctrine_Query::create()
            ->select()
            ->from($this->getModelClass() . ' r')
            ->where('r.reset_key = ?', $resetKey)
            ->andWhere('r.user_id = ?', $userId)
            ->fetchOne();

        return $result;
    }

    public function deleteRequests($userId)
    {
        $delete = Doctrine_Query::create()
            ->delete($this->getModelClass() . ' r')
            ->where('r.user_id = ?', $userId)
            ->execute();

        if (!$delete || count($delete) < 1) {
        	throw new RedCross_Gateway_Exception('Something is wrong somewhere. Affected rows were less than 1.');
        }
        return true;
    }

}